package com.idea.common.result;

import java.io.Serializable;

import com.idea.common.utils.ThreadLocalGson;

/**
 * @author xumin
 * @since 2012-6-13
 * 
 */
public class Result<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 558070259079456891L;

	private T content;

	private boolean success = true;

	private String message = "";

	public String resultType = "Result";

	public static <T> Result<T> buildSuccessResult(T content) {
		Result<T> result = new Result<T>();
		result.setContent(content);
		return result;
	}

	public static <T> Result<T> buildFailedResult(String message) {
		Result<T> result = new Result<T>();
		result.setSuccess(false);
		result.setMessage(message);
		return result;
	}

	public T getContent() {
		return content;
	}

	public Result<T> setContent(T content) {
		this.content = content;
		return this;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String toJson() {
		return ThreadLocalGson.getGson().toJson(this,this.getClass());
	}

	public String getResultType() {
		return resultType;
	}

	public void setResultType(String resultType) {
		this.resultType = resultType;
	}

	@Override
	public String toString() {
		return toJson();
	}

}
